var gameConfig = cc.Class({
    properties: {
       level:1,         //关卡
       ballSkin:"ball_00",   //现在使用的球皮肤
       tangGanSkin:"skin_00",//弹杆皮肤,
       ballUnlockArr:[],    //球已解锁皮肤名称
       ganUnlockArr:[],     //球杆已结束名称
       gold:0,  //钻石
       key:0,   //钥匙
       ballSkinUrl:"shop/ball/ball_", //求皮肤地址
       tangGanSkinUrl:"shop/tangGan/gan_",  //弹杆皮肤地址
       isOpenSound:1,//是否开启音效
       isOpenMusic:1,//是否开启背景音乐
    },

    init(){
        let level = this.getGameConfigData("level");
        let ballSkin = this.getGameConfigData("ballSkin");
        let ganSkin = this.getGameConfigData("ganSkin");
        let goldNum = this.getGameConfigData("goldNum");
        let keyNum = this.getGameConfigData("keyNum");
        let ballArr = this.getGameConfigData("ballUnlockArr");
        let ganArr = this.getGameConfigData("ganUnlockArr");
        let sound = this.getGameConfigData("isOpenSound");
        let music = this.getGameConfigData("isOpenMusic");

        if(level == null || level < 0)level = 1;
        this.saveLevel(level);

        if(ballSkin == null || ballSkin.indexOf("ball") == -1)ballSkin = "ball_00";
        this.setDefualtBallSkin(ballSkin);

        if(ganSkin == null)ganSkin = "gan_00";
        this.setTangGanSkin(ganSkin);

        if(goldNum == null)goldNum = 600;
        this.setGoldNumber(goldNum);

        if(keyNum == null)keyNum = 0;
        this.setKeyNumber(keyNum);

        if(ballArr == null)ballArr = 0;
        this.setBallUnlockArr(ballArr);

        if(ganArr == null)ganArr = 0;
        this.setGanUnlockArr(ganArr);

        if(sound == null)sound = 1;
        this.setGameSound(sound);

        if(music == null)music = 1;
        this.setGameMusic(music);
    },

    saveLevel(level){
        this.level = level;
        cc.sys.localStorage.setItem("level", level);
    },

    setDefualtBallSkin(ballSkin){
        this.ballSkin = ballSkin;
        cc.sys.localStorage.setItem("ballSkin", ballSkin);
    },

    setTangGanSkin(ganSkin){
        this.tangGanSkin = ganSkin;
        cc.sys.localStorage.setItem("ganSkin", ganSkin);
    },

    setGoldNumber(goldNum){
        this.gold = goldNum;
        cc.sys.localStorage.setItem("goldNum", goldNum);
    },

    setGameSound(sound){
        this.isOpenSound = sound;
        cc.sys.localStorage.setItem("isOpenSound", sound);
    },

    setGameMusic(music){
        this.isOpenMusic = music;
        cc.sys.localStorage.setItem("isOpenMusic", music);
    },

    setKeyNumber(keyNum){
        this.key = keyNum;
        cc.sys.localStorage.setItem("keyNum", keyNum);
    },

    setBallUnlockArr(ball){
        if(ball == 0)
        {
            this.ballUnlockArr = "00,";
            // this.ballUnlockArr[0] = "00";
            // this.ballUnlockArr.push(ball);
        }
        else this.ballUnlockArr = ball;
        cc.sys.localStorage.setItem("ballUnlockArr", this.ballUnlockArr);
    },

    setGanUnlockArr(gan){
        if(gan == 0)
        {
            // this.ganUnlockArr = [];
            this.ganUnlockArr = "00,";
            // this.ganUnlockArr[1] = "01";
            // this.ganUnlockArr[2] = "02";
            // this.ganUnlockArr[3] = "03";
            // this.ganUnlockArr.push(gan)
        }
        else this.ganUnlockArr = gan;
        cc.sys.localStorage.setItem("ganUnlockArr", this.ganUnlockArr);
    },

    getGameConfigData(config){
        let data = cc.sys.localStorage.getItem(config);
        return data;
    },
});

module.gameConfig = gameConfig;
